/**
 * 诊断管理初始化
 */
var CdcDiagnosis = {
    id: "CdcDiagnosisTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
CdcDiagnosis.initColumn = function () {
    return [
        {title: '序号',width:50,formatter: function (value, row, index) {return index+1;}},
        {title: '分类', field: 'busDiagCate.description', align: 'center', valign: 'middle', sortable: true, width:100},
        {title: '类型', field: 'busDiagType.description', align: 'center', valign: 'middle', sortable: true, width:100},
        {title: '描述', field: 'description', align: 'center', valign: 'middle', sortable: true, width:150},
        {title: 'ICD10', field: 'icd10', align: 'center', valign: 'middle', sortable: true, width:100},
        {title: '是否主诊断', field: 'isMain', align: 'center', valign: 'middle', sortable: true, width:150,formatter:function(value,row,index) {
            return value?"是":"否";
        }},
        {title: '状态', field: 'busDiagStatus.description', align: 'center', valign: 'middle', sortable: true, width:100},
        {title: '诊断日期', field: 'diagDate', align: 'center', valign: 'middle', sortable: true, width:150},
        {title: '发病日期', field: 'attackDate', align: 'center', valign: 'middle', sortable: true, width:150},
        {title: '来源', field: 'busDiagSource.description', align: 'center', valign: 'middle', sortable: true, width:150},
        {title: '备注', field: 'note', align: 'center', valign: 'middle', sortable: true, width:150},
        {title: '业务数据类型', field: 'data.description', align: 'center', valign: 'middle', sortable: true, width:120},
        {title: '是否有效', field: 'isActive', align: 'center', valign: 'middle', sortable: true, width:100,formatter:function(value,row,index) {
            return value?"是":"否";
        }}
    ];
};

/**
 * 检查是否选中
 */
CdcDiagnosis.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if(selected.length == 0){
        Sys.info("请先选中表格中的某一记录！");
        return false;
    }else{
        CdcDiagnosis.seItem = selected[0];
        return true;
    }
};
CdcDiagnosis.query = function () {
    if ((EpisodeIDTable.selEpisode)&&(EpisodeIDTable.selEpisode.id)) {
        var queryData=queryData = '{"NotQuery":"false","episodeId":"' + EpisodeIDTable.selEpisode.id + '"}';
        queryData = JSON.parse(queryData);
        CdcDiagnosis.table.clear();
        CdcDiagnosis.table.refresh({ query: queryData });
    }else{
        Sys.info('请先选择患者！' );
    }
};

$(function () {
    var defaultColunms = CdcDiagnosis.initColumn();
    var table = new BSTable(CdcDiagnosis.id, Sys.backendPath + "/cdc/cdcdiagnosis/list", defaultColunms);
    table.setPaginationType("server");
    table.setShowRefresh(false);
    table.setShowColumns(false);
    table.setShowToggle(false);
    table.setShowExport(false);
    table.setSubHead(30);
    table.setQueryParams({ NotQuery: true });
    CdcDiagnosis.table = table.init();
    CdcDiagnosis.query();
});
